package com.leyou.page.handler;

import com.leyou.page.entity.Sku;
import com.leyou.page.service.GoodsPageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import top.javatool.canal.client.annotation.CanalTable;
import top.javatool.canal.client.handler.EntryHandler;

//编写监听器,监听canal变化
//当数据库发生变化 同步redis中数据
@CanalTable(value = "tb_sku")
@Component
public class SkuHandler implements EntryHandler<Sku> {

    @Autowired
    private GoodsPageService goodsPageService;

    //sku表发生 增 操作
    @Override
    public void insert(Sku sku) {
        goodsPageService.loadSkuListData(sku.getSpuId());
    }

    //sku表发生 改 操作
    @Override
    public void update(Sku before, Sku after) {
        goodsPageService.loadSkuListData(after.getSpuId());
    }

    //sku表发生 删 操作
    @Override
    public void delete(Sku sku) {
        goodsPageService.deleteSku(sku.getSpuId());
    }
}
